#include <iostream>
#include <string>
namespace display
{
    int   x_push[7];   //this is the PUSH-Memory Array
    int   pixel[7][7]; //This is the Display-Output.

    void x(int x)
    {
        std::cout << "Pixel " << x << " saved to push-memory!" << std::endl;
        display::x_push[x] = 1;
    }
    void y(int y)
    {
        using namespace display;
        int i;
        int y_inverted = 8 - y;
        for (i = 1; i < 8; i++)
        {
            pixel[y_inverted][i] = x_push[i];
        }
        std::cout << "PUSH-Memory set to y " << y << " on the screen!" << std::endl;
    }
    void show_push()
    {
        using namespace std;
        cout << "PUSH-Memory:" << endl;
        cout << display::x_push[1] << " " << display::x_push[2] << " " << display::x_push[3] << " " << display::x_push[4] << " " << display::x_push[5] << " " << display::x_push[6] << " " << display::x_push[7] << " " << endl;
    }
    void show()
    {
        using namespace std;
        using namespace display;
        int i;
        for (i = 1; i < 8; i++)
        {
            cout << pixel[i][1] << " " << pixel[i][2] << " " << pixel[i][3] << " " << pixel[i][4] << " " << pixel[i][5] << " " << pixel[i][6] << " " << pixel[i][7] << endl;
        }
    }
    void delete_display()
    {
        for (int i = 1; i < 8; i++)
        {
            display::pixel[i][1] = 0;
            display::pixel[i][2] = 0;
            display::pixel[i][3] = 0;
            display::pixel[i][4] = 0;
            display::pixel[i][5] = 0;
            display::pixel[i][6] = 0;
            display::pixel[i][7] = 0;
        }
    }
    void delete_push()
    {
        display::x_push[1] = 0;
        display::x_push[2] = 0;
        display::x_push[3] = 0;
        display::x_push[4] = 0;
        display::x_push[5] = 0;
        display::x_push[6] = 0;
        display::x_push[7] = 0;
    }
    void delete_all()
    {
        display::delete_display();
        display::delete_push();
    }
}
void help()
{
    using namespace std;
    cout << "s" << endl;
    cout << "   - d          Outputs the display to the screen" << endl;
    cout << "   - p          Outputs the PUSH-Memory to the screen" << endl;
    cout << "d" << endl;
    cout << "   - d          Clears the display" << endl;
    cout << "   - p          Clears the PUSH-Memory" << endl;
    cout << "   - a          Deletes all Variables" << endl;
    cout << "x" << endl;
    cout << "   - <1 - 7>    Writes a Pixel to the PUSH-Memory on the coordinate X" << endl;
    cout << "y" << endl;
    cout << "   - <1 - 7>    Writes the PUSH-Memory on the Screen (line Y)" << endl;
    cout << "exit            Exits the Program" << endl;
    cout << "help            Opens the Help-Menue" << endl;
}
int main()
{
    using namespace std;
    bool end = false;
    string s_input;
    int i_input;

    //Set the Arrays to Zero...
    display::delete_all();

    cout << "GPU-SIMULATOR" << endl << "       - MineCraft Redstone GPU" << endl << "       - Build by rfmRuckys & maximaximal" << endl << "       - Simulator coded by maximaximal (Max Heisinger)" << endl << "       - type in \"help\" for available commands" << endl;
    for (;end != true;)
    {
        cout << ">";
        cin >> s_input;
        if (s_input == "s")
        {
            cin >> s_input;
            if (s_input == "d") (display::show());
            if (s_input == "p") (display::show_push());
            s_input = "";
        }
        if (s_input == "x")
        {
            cin >> i_input;
            if (i_input > 7) (cout << " ! The display is only 7 Pixel wide !" << endl);
            else (display::x(i_input));
             s_input = "";
        }
        if (s_input == "y")
        {
            cin >> i_input;
            if (i_input > 7) (cout << " ! The display is only 7 Pixel tall !" << endl);
            else (display::y(i_input));
            s_input = "";
        }
        if (s_input == "d")
        {
            cin >> s_input;
            if (s_input == "d") (display::delete_display());
            if (s_input == "p") (display::delete_push());
            if (s_input == "a") (display::delete_all());
            s_input = "";
        }
        if (s_input == "help") (help());
        if (s_input == "exit") (cout << endl << "Closing the simulator..." << endl, end = true);    //Exit the program
    }
}
